package com.fancy.learncenter.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.VitaDetailDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.fancy.learncenter.utils.ToastUtil;
import com.fancy.learncenter.utils.Utils;
import com.fancy.learncenter.view.PopupWindowEducationType;
import com.superservice.lya.R;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WorkExperienceActivity extends BaseActivity {


    String educationId = "";

    String resumeId;

    VitaDetailDataBean.WorkListBean workListBean;

    @Bind(R.id.start_time)
    TextView startTime;
    @Bind(R.id.end_time)
    TextView endTime;
    @Bind(R.id.company_tv)
    EditText companyTv;
    @Bind(R.id.work_tv)
    EditText workTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_experience, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);
        initToolbar("工作经历");

        resumeId = getIntent().getStringExtra("resumeId");
        workListBean = getIntent().getParcelableExtra("WorkListBean");

        if (workListBean != null) {
            companyTv.setText(workListBean.getCompany_name());
            workTv.setText(workListBean.getPostion());
            startTime.setText(workListBean.getAdd_time());
            endTime.setText(workListBean.getEnd_time());
        }

        pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                // 这里回调过来的v,就是show()方法里面所添加的 View 参数，如果show的时候没有添加参数，v则为null
                startTime.setText(Utils.getTime(date));
            }
        })
                .setType(new boolean[]{true, true, true, false, false, false})
                .build();
        edTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                // 这里回调过来的v,就是show()方法里面所添加的 View 参数，如果show的时候没有添加参数，v则为null
                endTime.setText(Utils.getTime(date));
            }
        })
                .setType(new boolean[]{true, true, true, false, false, false})
                .build();
    }

    PopupWindowEducationType educationType;

    TimePickerView pvTime;
    TimePickerView edTime;

    @OnClick({R.id.start_time, R.id.end_time, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.start_time:
                pvTime.show();
                break;
            case R.id.end_time:
                edTime.show();
                break;
            case R.id.education_tv:
                educationType.showPopupWindow();
                break;
            case R.id.submit:

                editPersonVita();
                break;
        }
    }


    private void editPersonVita() {
        Map map = new HashMap();

        map.put("startTime", startTime.getText().toString());

        map.put("endTime", endTime.getText().toString());

        map.put("resumeId", resumeId);

        map.put("postion", workTv.getText().toString());

        map.put("companyName", companyTv.getText().toString());


        if (workListBean != null) {
            map.put("workId", workListBean.getId());

        }

        HttpMehtod.getInstance().doWorkExperience(map, new IdeaObserver<BaseDataBean>(this) {

            @Override
            public void onSuccess(BaseDataBean listBaseDataBean) {
                ToastUtil.show("资料已更新");
                finish();
            }

            @Override
            public void onFail(int errorCode) {

            }
        });
    }
}
